import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class BlurMask extends StatelessWidget {
  const BlurMask(
      {required this.child, required this.barrierDismissible, Key? key})
      : super(key: key);

  final Widget child;
  final bool barrierDismissible;

  @override
  Widget build(BuildContext context) {
    final mask = ClipRect(
      child: Stack(
        children: [
          BackdropFilter(
            filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
            child: Container(
              color: Colors.black.withOpacity(0.5),
            ),
          ),
          child,
        ],
      ),
    );

    return barrierDismissible
        ? InkWell(
      onTap: () {
        Get.back();
      },
      child: mask,
    )
        : mask;
  }

  static show(Widget child, {bool barrierDismissible = true}) {
    showCupertinoDialog(
      context: Get.context!,
      builder: (context) => BlurMask(
        barrierDismissible: barrierDismissible,
        child: child,
      ),
    );
  }
}
